package com.hwadee.teachingprocessmanagementsystem.service.base.impl;

import com.hwadee.teachingprocessmanagementsystem.entity.ExamMethod;
import com.hwadee.teachingprocessmanagementsystem.dao.ExamMethodDao;
import com.hwadee.teachingprocessmanagementsystem.service.base.ExamMethodService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * (ExamMethod)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 14:20:03
 */
@Service("examMethodService")
public class ExamMethodServiceImpl implements ExamMethodService {
    @Resource
    private ExamMethodDao examMethodDao;

    /**
     * 通过ID查询单条数据
     *
     * @param examMethodsId 主键
     * @return 实例对象
     */
    @Override
    public ExamMethod queryById(Integer examMethodsId) {
        return this.examMethodDao.queryById(examMethodsId);
    }

    /**
     * 分页查询
     *
     * @param examMethod 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ExamMethod> queryByPage(ExamMethod examMethod, PageRequest pageRequest) {
        long total = this.examMethodDao.count(examMethod);
        return new PageImpl<>(this.examMethodDao.queryAllByLimit(examMethod, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param examMethod 实例对象
     * @return 实例对象
     */
    @Override
    public ExamMethod insert(ExamMethod examMethod) {
        this.examMethodDao.insert(examMethod);
        return examMethod;
    }

    /**
     * 修改数据
     *
     * @param examMethod 实例对象
     * @return 实例对象
     */
    @Override
    public ExamMethod update(ExamMethod examMethod) {
        this.examMethodDao.update(examMethod);
        return this.queryById(examMethod.getExamMethodsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param examMethodsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer examMethodsId) {
        return this.examMethodDao.deleteById(examMethodsId) > 0;
    }
}
